package com.xcdh.learn.commons;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xcdh.learn.entity.BaseEntity;
import com.xcdh.learn.entity.Books;


import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Condition {
    public static <T> QueryWrapper<T> getQueryWrapper(T entity) {
        QueryWrapper<T> queryWrapper = new QueryWrapper<>(entity);
        return  queryWrapper;
    }

    public static <T> QueryWrapper<T> getQueryWrapper(T entity , String... columns ) {
        return new QueryWrapper<>(entity ,columns);
    }

    public static <T> QueryWrapper<T> emptyWrapper(T entity){
        return new QueryWrapper<>(entity) ;
    }

    public static  <T> IPage<T> getPage(Query query){
        Page<T> page = new Page<>(query.getCurrent() , query.getSize());
        return page ;
    }

    public static String[] getColumns(Class cls){
        Field[] fields = cls.getDeclaredFields();
        return Arrays.stream(fields).map((field)->field.getName()).filter((name)->!"serialVersionUID".equals(name)).toArray(String[]::new) ;
    }

    public static Map<String,Object> getQueryMap(BaseEntity entity){
        Map<String,Object> map = new HashMap<>() ;
        return map ;
    }



    public static void main(String[] args) {
        System.out.println(Arrays.toString(getColumns(Books.class )));
    }
}
